package com.lwy.aspect;


import com.lwy.setter.RoleUser;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.FieldSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;


@Aspect
@Component
public class RoleUserAspect {

    @Pointcut("@annotation(com.lwy.setter.RoleUser)")
    public void pointcut() {
        System.out.println("RoleUserAspect logPoint");
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        FieldSignature signature = (FieldSignature) joinPoint.getSignature();
        Field field = signature.getField();
        RoleUser annotation = field.getAnnotation(RoleUser.class);
        return annotation.role();
    }
}
